package com.iteaj.iot.client.mqtt.impl;

import com.iteaj.iot.AbstractProtocol;
import com.iteaj.iot.client.ClientConnectProperties;
import com.iteaj.iot.client.MultiClientManager;
import com.iteaj.iot.client.mqtt.MessagePublishListener;
import com.iteaj.iot.client.mqtt.MqttClientComponent;
import com.iteaj.iot.client.mqtt.MqttConnectProperties;
import io.netty.handler.codec.mqtt.MqttTopicSubscription;

import java.util.List;

public class MqttDefaultClientComponent extends MqttClientComponent<MqttDefaultClientMessage> {

    private static final String NAME = "MQTT";
    private static final String DESC = "MQTT默认客户端实现(V3.1+)";

    private MqttDefaultImplProcessor matcher;

    public MqttDefaultClientComponent(MqttDefaultImplProcessor matcher) {
        this.matcher = matcher;
    }

    public MqttDefaultClientComponent(MqttConnectProperties config, MqttDefaultImplProcessor matcher) {
        super(config);
        this.matcher = matcher;
    }

    public MqttDefaultClientComponent(MqttConnectProperties config, MultiClientManager clientManager, MqttDefaultImplProcessor matcher) {
        super(config, clientManager);
        this.matcher = matcher;
    }

    public MqttDefaultClientComponent(ClientConnectProperties config, MultiClientManager clientManager
            , MessagePublishListener publishListener, MqttDefaultImplProcessor matcher) {
        super(config, clientManager, publishListener);
        this.matcher = matcher;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getDesc() {
        return DESC;
    }

    @Override
    public AbstractProtocol getProtocol(MqttDefaultClientMessage message) {
        return this.getMatcher().getProtocol(message, this);
    }

    @Override
    protected List<MqttTopicSubscription> doSubscribe(MqttConnectProperties client) {
        return this.getMatcher().subscribe(client);
    }

    @Override
    public Class<MqttDefaultClientMessage> getMessageClass() {
        return MqttDefaultClientMessage.class;
    }

    public MqttDefaultImplProcessor getMatcher() {
        return matcher;
    }
}
